package com.woniuxy01;

interface MyInterface{
    void yyy();
}
class Xxx{
    void test(MyInterface myInterface){
        myInterface.yyy();
    }
}
class MyInterfaceImpl implements MyInterface{
    @Override
    public void yyy() {
        System.out.println("MyInterfaceImpl--yyy");
    }
}

class MyInterfaceImpl2 implements MyInterface{
    @Override
    public void yyy() {
        System.out.println("MyInterfaceImpl2--yyy");
    }
}
public class Test05 {
    public static void main(String[] args) {
        Xxx xxx=new Xxx();
        MyInterface myInterface = new MyInterfaceImpl();
        //形参是接口，定义接口的实现类，实参，接口的实现类的对象
        xxx.test(myInterface);
        //实参，接口的实现类的对象:匿名对象
        xxx.test(new MyInterfaceImpl2());

        //匿名内部类：本质接口的实现类的对象
        //没有定义实现类，
        xxx.test(new MyInterface() {
            @Override
            public void yyy() {
                System.out.println("1111");
            }
        });

        xxx.test(new MyInterface() {
            @Override
            public void yyy() {
                System.out.println("22222");
            }
        });
        xxx.test(new MyInterface() {
            @Override
            public void yyy() {
                System.out.println("111");
            }
        });
    }
}
